
using System;
using System.ComponentModel;
using System.ComponentModel.Design;
using System.Collections.Generic;
using System.Diagnostics;
using System.Text;
using System.Windows.Forms;
using System.Drawing;
using System.Data;
using System.Collections;
using System.Drawing.Design;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using GuavaData;



namespace GuavaLib
{
    public partial class GTabControl : TabControl, Guava
    {
        string gname;
        System.Windows.Forms.Label lab;

        public GTabControl()
        {
            InitializeComponent();
            base.TabPages.Clear();
        }

        public System.Windows.Forms.Label Label
        {
            get { return lab; }
            set { lab = value; }
        }

        #region Guava Members

        [Browsable(false)]
        public LaunchType LType
        {
            get
            {
                return LaunchType.NA;
            }
        }

        [Browsable(false)]
        public ControlType CType
        {
            get
            {
                return ControlType.Container;
            }
        }

        [Browsable(false)]
        public string GText
        {
            get
            {
                if (this.lab == null) return null;
                return this.lab.Name;
            }
        }

        public string GName
        {
            get
            {
                if (gname == null) return this.Name;
                return gname;
            }
            set
            {
                gname = value;
            }
        }

        [Browsable(false)]
        public Point GLocation
        {
            get { return this.Location; }
        }

        [Browsable(false)]
        public Size GSize
        {
            get { return this.Size; }
        }

        [Browsable(false)]
        public List<Guava> GComponents
        {
            get
            {
                List<Guava> lg = new List<Guava>();

                foreach (TabPage tp in this.TabPages) lg.Add(new GTabPage(tp));

                return lg;
            }
        }

        public void GBind(string table, int i)
        {
            foreach (Guava c in GComponents)
            {
                c.GBind(table, i);
            }
        }

        [Browsable(false)]
        public string GDefault
        {
            get { return null; }
        }

        [Browsable(false)]
        public string GToolTip
        {
            get
            {
                Control p = this.TopLevelControl;
                if (!(p is Guava)) return null;
                ToolTip t = (p as GuavaForm).GToolTipProvider;
                if (t == null) return null;

                // Fetch the tooltip and return it
                return t.GetToolTip(this);
            }
        }

        [Browsable(false)]
        public GuavaData.Domain.Domain GDomain
        {
            get
            {
                return null;
            }
        }

        public Guava this[string s]
        {
            get
            {
                foreach (Guava g in this.GComponents) if (g.GName == s) return g;
                return null;
            }
        }
        #endregion
    }

    internal class GTabPage : TabPage, Guava
    {
        TabPage tp;
        
        public GTabPage(TabPage tp)
        {
            this.tp = tp;
        }

        #region Guava Members

        [Browsable(false)]
        public LaunchType LType
        {
            get
            {
                return LaunchType.NA;
            }
        }

        [Browsable(false)]
        public ControlType CType
        {
            get
            {
                return ControlType.Container;
            }
        }

        [Browsable(false)]
        public string GText
        {
            get
            {
                return tp.Text;
            }
        }

        public string GName
        {
            get
            {
                string temp = tp.Text;
                string[] sa = new string[] { " ", "/", "#", "@", "!", "$", "%", "^", "&", "*", "(", ")" }; 
                foreach (string s in sa) temp = temp.Replace(s, "");
                return temp;
            }
            set
            {
                return;
            }
        }

        [Browsable(false)]
        public Point GLocation
        {
            get { return tp.Location; }
        }

        [Browsable(false)]
        public Size GSize
        {
            get { return tp.Size; }
        }

        [Browsable(false)]
        public List<Guava> GComponents
        {
            get
            {
                List<Guava> lg = new List<Guava>();

                foreach (Control c in tp.Controls)
                {
                    if (c is Guava) lg.Add((Guava)c);
                }

                return lg;
            }
        }

        public void GBind(string table, int i)
        {
            foreach (Guava c in GComponents)
            {
                c.GBind(table, i);
            }
        }

        [Browsable(false)]
        public string GDefault
        {
            get { return null; }

        }

        [Browsable(false)]
        public string GToolTip
        {
            get
            {
                return tp.ToolTipText;
            }
        }

        [Browsable(false)]
        public GuavaData.Domain.Domain GDomain
        {
            get
            {
                return null;
            }
        }

        public Guava this[string s]
        {
            get
            {
                foreach (Guava g in this.GComponents) if (g.GName == s) return g;
                return null;
            }
        }
        #endregion

    }
}